package com.jues.huichain;

import android.content.Context;

import com.alibaba.android.arouter.facade.Postcard;
import com.alibaba.android.arouter.facade.annotation.Interceptor;
import com.alibaba.android.arouter.facade.callback.InterceptorCallback;
import com.alibaba.android.arouter.facade.template.IInterceptor;
import com.alibaba.android.arouter.launcher.ARouter;

import health.lm.com.data.App;
import health.lm.com.router.ARouterConstant;

/**
 * 登录拦截器
 * 根据每个页面的设置来判断需不需要跳转到登录页面
 */
@Interceptor(priority = 1)
public class LoginInterceptor implements IInterceptor {
    Context mContext;

    @Override
    public void process(final Postcard postcard, final InterceptorCallback callback) {
        if(postcard.getExtra()== ARouterConstant.NEED_LOGIN){
            if(App.getModel().isNeed_login()){
                ARouter.getInstance().build(ARouterConstant.LoginActivity)
                        .withString(ARouterConstant.JUMP_PATH, postcard.getPath())
                        .withBundle(ARouterConstant.JUMP_BUNDLE,postcard.getExtras())
                        .navigation(mContext);
            }else {
                callback.onContinue(postcard);
            }
        }else {
            callback.onContinue(postcard);
        }

    }

    @Override
    public void init(Context context) {
        mContext= context;
    }
}
